﻿function Utilities() {

    Utilities.prototype.imageToolTip = function (elemID, imgSrc, imgClass) {
        $(function () {
            var offsetX = 30;
            var offsetY = -50;

            $(elemID).hover(function (e) {
                //mouse on
                $('<img id="largeImage" src="' + imgSrc + '" alt="image" />')
                    .css('top', e.pageY + offsetY)
                    .css('left', e.pageX + offsetX)
                    .appendTo('body')
                    .hide()
                    .fadeIn(500);
            }, function () {
                // mouse off
                $(imgClass).remove();
            });

            $(elemID).mousemove(function (e) {
                $(imgClass)
                    .css('top', e.pageY + offsetY)
                    .css('left', e.pageX + offsetX);
            });
        });
    };

    Utilities.prototype.createModal = function (modalDiv, targetClick) {
        $(function () {

            $(modalDiv).dialog({
                autoOpen: false,
                show: "blind",
                hide: "blind",
                modal: true,
                height: 420,
                width: 500,
                resizable: false
            });

            $(targetClick).click(function () {

                // increase the default animation speed to exaggerate the effect
                $.fx.speeds._default = 1000;
                $(modalDiv).dialog("open");
                return false;
            });
        });
    };

    Utilities.prototype.createContentSlide = function (next, back, boxOne, boxTwo) {
        $(function () {
            // cache DOM Elements
            var btNext = $(next);
            var btBack = $(back);
            var containerOne = $(boxOne);
            var containerTwo = $(boxTwo);

            // hide the second container onLoad
            containerTwo.hide();

            btNext.click(function () {
                containerOne.animate({
                    'left': '-2000px'
                }, 1000);
                containerTwo.show(1);
                containerTwo.animate({
                    'left': '104px'
                }, 1000);
            });

            btBack.click(function () {
                containerTwo.animate({
                    'left': '2000px'
                }, 1000);
                containerOne.animate({
                    'left': '104px'
                }, 1000);
                containerTwo.hide(1);
            });
        });
    };

    Utilities.prototype.createGoogleMap = function (mapDiv, mapCenter, mapMarker, controlDiv) {
        $(function () {
            var map = new GMap2($(mapDiv).get(0));
            map.setCenter(mapCenter, 16);
            var markers = [];
            var point = mapMarker;
            marker = new GMarker(point);
            map.addOverlay(marker);

            var controls = $('<div id="controls" />').appendTo(controlDiv);

            $(iconHTML("plus"))
            .css({ top: '84px', left: '32px' })
            .click(function () {
                map.setZoom(map.getZoom() + 1);
                $("#map-slider").slider("value", map.getZoom());
            })
            .appendTo(controls);

            $(iconHTML("minus"))
            .css({ top: '325px', left: '32px' })
            .click(function () {
                map.setZoom(map.getZoom() - 1);
                $("#map-slider").slider("value", map.getZoom());
            })
            .appendTo(controls);

            var zoomChanged = false;
            $('<div id="map-slider" />').height(200)
            .slider({
                orientation: "vertical",
                min: 0, max: 19, step: 1, value: map.getZoom(),
                stop: function () {
                    map.setZoom($(this).slider("value"));
                }
            })
            .css({ top: '115px', left: '38px', position: 'absolute' })
            .appendTo(controls);

            function iconHTML(type) {
                switch (type) {
                    case "up": iconClass = 'ui-icon-circle-arrow-n'; break;
                    case "down": iconClass = 'ui-icon-circle-arrow-s'; break;
                    case "left": iconClass = 'ui-icon-circle-arrow-w'; break;
                    case "right": iconClass = 'ui-icon-circle-arrow-e'; break;
                    case "plus": iconClass = 'ui-icon-circle-plus'; break;
                    case "minus": iconClass = 'ui-icon-circle-minus'; break;
                    case "close": iconClass = 'ui-icon-closethick'; break;
                }
                return '<div class="icon ui-state-default ui-corner-all"><span class="ui-icon ' + iconClass + '" /></div>';
            }

        });
    };

    Utilities.prototype.createTabbing = function (tabs, section) {
        $(function () {
            var tabHeadings = $(tabs);
            tabHeadings.click(function (e) {
                e.preventDefault;
                var clickId = e.target.id;
                var correspondingSection = $(section);
                var divs = correspondingSection.children();

                var notSelected = divs.not(clickId);
                notSelected.hide()
                               .fadeOut(500);

                var selected = $(clickId);
                selected.hide()
                            .fadeIn(500);

                return false;
            });
        });
    };

    Utilities.prototype.createKyanEffect = function (kyanWrap, kyanFront) {
        //Method: kyan technique
        //Description: This function takes all the wrap classes in the
        // kyanContainer and animates the top down 300 pixels on hover  
        // so the image below it will show. The image returns to it's 
        // orginal positon after the hover is released.
        $(function () {
            $(kyanWrap).hover(function () {
                $(this).children(kyanFront).stop().animate({
                    "top": '300px'
                }, 800);
            }, function () {
                $(this).children(kyanFront).stop().animate({
                    "top": '0'
                }, 500);
            });
        }); 
    };

    Utilities.prototype.createTwitterSearch = function (div, button, searchValue) {
        $(function () {
            var bt = $(button);
            bt.click(function () {
                $(div).twitterSearch(searchValue);
                bt.hide(500);
            });
        });
    };
}
